<?

	include_once("cmsConfig.php");
	
	define('ORDER_ITEM_IMAGE_ORIGINAL', 1);
	define('ORDER_ITEM_IMAGE_SMALL_ORIGINAL', 2);
	define('IMAGE_SIZE_THUMB',3);
	define('IMAGE_SIZE_SMALL',4);
	define('IMAGE_SIZE_MEDIUM',5);	
	

	class GripLockOrderItem extends CmsOrderItem {
		
		//question to who ever reads this.. why are these here and not in the kvc things?
		
		var $orderItemType = null;
		var $isGift = false;
		
		function GripLockOrderItem(){
			parent::CmsOrderItem();
			
			$this->keys = array_merge_recursive(
				array(				
					EXTRACT_NUMBER =>array("productId")
		//			EXTRACT_STRING => array("shortdescription")
				),
				$this->keys
			);			
		//	
			$this->requiredKeys = array_merge(
				array("productId"),
				$this->requiredKeys
			);			
		//	
			$this->dataModelKeyMapping = array_merge(
				$this->dataModelKeyMapping,
				array(
					"productId" => "shortdescription"
			));			
		}
		
		function price(){
			//this needs adjustmet for currency
			global $currency;
			
			$oc = $this->valueForKey('orderContainer');
			
						
			if (is_string($oc)) {			
				$oc = $_SESSION['_CMSKVC'][$oc];
				$cur = $oc->valueForKey('currency');				
			}
	
			if (null == $cur) {
				//$cur = "USD";
				$cur = $currency;
			}
			
			$price = parent::price();
			$cmsDocument = $this->valueForKey('cmsDocument');
			$productDoc = $cmsDocument->openDocumentFromCache($this->valueForKey('productId'));
			
			switch ($cur){	
				case "NZD":
					$price = $productDoc->extra6;		
				break;		
				case "AUD":
					$price = $productDoc->extra7;		
				break;		
						
				case "GBP":
					$price = $productDoc->extra9;
				break;
	

				case "EUR":
					$price = $productDoc->extra10;
				break;
				
				default:
				case "USD":
					$price = $productDoc->extra8;
				break;				
			}

			return $price;
		}
		
		
		function subTotal() {
			return $this->valueForKey('price') * $this->valueForKey('quantity');
		}
		
		function cmsDocument() {
			$db = &$_SESSION['db'];
			return new CmsDocument($db);
		}		
		
		function imageDataForSize($imageSize) {
			$data =null;
			$productId = $this->valueForKey('productId');
			
			$cmsDocument = $this->valueForKey('cmsDocument');
			$product = $cmsDocument->openDocumentFromCache($productId);

			if ($product) {
									
				$imageRow ='';// we need to work out wich image to get and scale on..

				if (!is_null($product->restricted)){
					$db = &$_SESSION['db'];
					$q = "SELECT content  FROM binarydata WHERE documentcode='".$product->documentcode ."' AND elementid=11142";
					

					$db->executeQuery($q);
					$row = null;
					$data = null;
					if ($db->numRows() == 1 && $row = $db->nextAssoc()) {
						$data = $row[ 'content' ];
					}
				}
				
			}
			return $data;
		}
		


	}


?>